package com.example.discover.repository

import androidx.annotation.WorkerThread
import com.example.discover.model.Book
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

@WorkerThread
class BookRepository @Inject constructor(private val bookDao: BookDao, private val bookWebService: BookWebService){

    fun getAll(): Flow<List<Book>> {
        return bookDao.getAll()
    }

    fun bookCount() : Flow<Int> = bookDao.getCount()

    fun get(isbn: String): Flow<Book>? {
        return bookDao.get(isbn)
    }

    fun insert(vararg books: Book) {
        //TODO: Update remote repository using bookWebService
        bookDao.insert(*books)
    }

    fun insert(books: List<Book>) {
        //TODO: Update remote repository using bookWebService
        bookDao.insert(books)
    }

    fun delete(isbn: String){

        bookWebService.deleteBook(isbn)

        bookDao.delete(isbn)
    }

    fun deleteAll(){
        //TODO: Update remote repository using bookWebService
        bookDao.deleteAll()
    }

    fun update(isbn: String,price: String){
        //TODO: Update remote repository using bookWebService
        bookDao.update(BookDao.Price(isbn,price))
    }

    fun update(book: Book){
        //TODO: Update remote repository using bookWebService
        bookDao.update(book)
    }
}